<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col>
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px" v-show="showSearch" >
          <el-form-item label="防伪码" prop="trackingCode">
            <el-input v-model="queryParams.trackingCode" placeholder="请输入防伪码" size="small" clearable style="width: 150px"/>
          </el-form-item>

          <el-form-item label="查询编号" prop="queryNumber">
            <el-input v-model="queryParams.queryNumber" placeholder="请输入查询编号" size="small" clearable style="width: 150px"/>
          </el-form-item>
          <el-form-item label="查询IP" prop="queryIp">
            <el-input v-model="queryParams.queryIp" placeholder="请输入查询IP" size="small" clearable style="width: 150px"/>
          </el-form-item>

          <el-form-item label="操作时间">
            <el-date-picker @change="handleQuery" v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
          </el-form-item>

          <el-form-item>
            <el-button type="primary"  size="mini" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery('queryForm')">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button  size="mini" :disabled="buttonDisabled(total)" type="primary" icon="el-icon-bottom-right" @click="handleExport('thisPage')" v-hasPermi="['exportTrackingQueryRecordList']" >导出本页</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button  size="mini" :disabled="buttonDisabled(total)" type="primary" icon="el-icon-download" v-hasPermi="['exportTrackingQueryRecordList']" @click="handleExport('All')">导出全部</el-button>
          </el-col>

          <right-toolbar :showSearch.sync="showSearch" @queryTable="queryTrackingQueryRecordPageResList" :columns="columns"></right-toolbar>
        </el-row>
        <el-table :stripe="true" v-loading="loading" :data="dataList" style="width: 100%" @sort-change='tableSortChange'>
          <el-table-column label="查询编号" align="left" prop="queryNumber" width="200" />
          <el-table-column label="防伪码" align="left" prop="trackingCode" width="200"/>
          <el-table-column label="浏览器" align="left" prop="queryUa"/>
          <el-table-column label="IP" align="left" prop="queryIp" width="200" />
          <el-table-column label="操作时间" align="center" prop="createTime" sortable='custom' width="200" />
        </el-table>
        <pagination v-show="total>0"  :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.rows" @pagination="queryTrackingQueryRecordPageResList"/>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import {queryTrackingQueryRecordPageResList, exportTrackingQueryRecordPageResList} from '@/api/tracking/trackingQueryRecord'
  //默认查询参数
  let defaultQueryParams = {
    queryNumber: undefined,
    startTime: undefined,
    endTime: undefined,
    queryIp: undefined,
    trackingNumber: undefined,
    trackingCode: undefined,
    page: 1,
    rows: 10
  }
  export default {
    name: 'trackingCodeQueryRecordAdmin',
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 显示搜索条件
        showSearch: true,
        //操作日志
        dataList: [],
        // 日期范围
        dateRange: [],
        // 查询参数
        queryParams: { ...defaultQueryParams },
        //列信息
        columns:[
          { fieldCode: 'trackingCode' , fieldName: '防伪码', visible: true},
          { fieldCode: 'queryNumber' , fieldName: '查询编号', visible: true},
          { fieldCode: 'queryUa' , fieldName: '浏览器', visible: true},
          { fieldCode: 'queryIp' , fieldName: 'IP', visible: true},
          { fieldCode: 'createTime' , fieldName: '操作时间', visible: true}
        ]
      }
    },
    created() {
      this.queryTrackingQueryRecordPageResList()
    },
    methods: {
      //排序
      tableSortChange(column) {
        //格式化排序参数，构建中
        this.orderByFormat(this.queryParams,column);
        //执行查询方法
        this.queryTrackingQueryRecordPageResList()
      },
      /** 查询防伪查询记录列表 */
      queryTrackingQueryRecordPageResList() {
        this.loading = true
        queryTrackingQueryRecordPageResList(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
            this.dataList = res.data.records
            this.total = res.data.total
          }
        ).finally(() => {
          //关闭加载特效
          this.loading = false
        })
      },
      /** 重置按钮操作 */
      resetQuery(fromId) {
        this.dateRange = []
        this.resetForm(fromId)
        this.handleQuery()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1
        this.queryTrackingQueryRecordPageResList()
      },
      /** 导出按钮操作 */
      handleExport(params) {
        //如果是导出本页则 去除分页参数
        if ('All' === params) {
          this.queryParams.rows = 0
        }
        let dataParams = { ...this.queryParams, ...{ excelFieldList: this.columns } }
        this.$confirm('是否确认导出数据?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          exportTrackingQueryRecordPageResList(dataParams, '防伪查询记录')
        })
      }
    }
  }
</script>
